var maps;
var map;
var comMove;
var comMove1;
var lv=0;
var number=0
var personPoint=new Object();
var computerF;
var computerF1;
//子弹数组
var bulletArray=new Array();

//当前方向
var direction=2;

//子弹发射
var fireBullet;

//方向
var bulletDirection;

var k=1;
//DOM加载完成后运行
function initGames(){
	//<embed src="mp3/start.wav" width="0" height="0">
	
	document.getElementById("game").innerHTML="";
	var num=document.getElementById("num")
	var music=document.createElement("embed");
	music.src="mp3/start.wav";
	music.width="0";
	music.height="0";
	num.appendChild(music)
	initMaps();
	initMapUI();
	keyDown();
	comMove=setInterval("computerMove()",1000);
	comMove1=setInterval("computerMove1()",1000);
	computerF=setInterval("redom()",1000);
	computerF1=setInterval("redom1()",1000);	
}
//导入地图到div中
function initMapUI(){
	//map.length=15		map[lv].length=13
	map=maps[lv];
	var div=$("#game");
	var pictureWidth=div.width()/map[lv].length;
	var pictureHeight=div.height()/map.length;
	for(var i=0;i<map.length;i++){
		for(var j=0;j<map[i].length;j++){
			if(map[i][j]=="p1tankU"){
				personPoint.x=j;
				personPoint.y=i;	
			}else if(map[i][j]=="enemy1D"){
				computerPoint.x=j;
				computerPoint.y=i;
			}else if(map[i][j]=="enemy1D1"){	
				computerPoint1.x=j;
				computerPoint1.y=i;
			}
			var img=document.createElement("img");
			img.src="img/"+map[i][j]+".gif";
			img.width=pictureWidth;
			img.height=pictureHeight;
//给img添加属性
			img.setAttribute("x",j);
			img.setAttribute("y",i);
			img.id=j+"-"+i;
			document.getElementById("game").appendChild(img);
		}
	}
}
//键盘事件
function keyDown(){
	$(window).keydown(function(event){
		var nextPoint=new Object();
		switch(event.keyCode) {
			case 65:
				//获取人物当前位置并且计算下一个位置
				nextPoint.x=personPoint.x-1;
				nextPoint.y=personPoint.y;
				//人物行走到下个位置
				nextPointValue(nextPoint);
				document.getElementById(personPoint.x+"-"+personPoint.y).src="img/p1tankL.gif";
				//记录方向
				direction=1;
				
			break;
			case 87:
				nextPoint.x=personPoint.x;
				nextPoint.y=personPoint.y-1;
				nextPointValue(nextPoint);
				document.getElementById(personPoint.x+"-"+personPoint.y).src="img/p1tankU.gif";
				direction=2;
			break;
			case 68:
				nextPoint.x=personPoint.x+1;
				nextPoint.y=personPoint.y;
				nextPointValue(nextPoint);
				document.getElementById(personPoint.x+"-"+personPoint.y).src="img/p1tankR.gif";
				direction=3;
			break;
			case 83:
				nextPoint.x=personPoint.x;
				nextPoint.y=personPoint.y+1;
				nextPointValue(nextPoint);
				document.getElementById(personPoint.x+"-"+personPoint.y).src="img/p1tankD.gif";
				direction=4;
			break;
			case 74:
				if(bulletArray.length!=0){
					
				}else{
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/fire.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					bullet();	
				}
			break;
	  	}
	})
}
//记录子弹数组
function bullet(){
	//记录方向
	bulletDirection=direction;
	//记录角色位置
	var	nextBullet=new Object();
	nextBullet.x=personPoint.x;
	nextBullet.y=personPoint.y;
	switch(bulletDirection){
		case 1:
			for(var i=0;i<(nextBullet.x );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x-i;
				nextBulletPoint.y=nextBullet.y;
				bulletArray.push(nextBulletPoint)
			}
		break;	
		case 2:
			for(var i=0;i<(nextBullet.y );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y-i;
				bulletArray.push(nextBulletPoint)
			}
		break;	
		case 3:
			for(var i=0;i<(map[lv].length-nextBullet.x-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x+i;
				nextBulletPoint.y=nextBullet.y;
				bulletArray.push(nextBulletPoint)
			}
		break;	
		case 4:
			for(var i=0;i<(map.length-nextBullet.y-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y+i;
				bulletArray.push(nextBulletPoint)
			}
		break;	
	}
	fireBullet=setInterval("openFire()",300);
}
//射击
function openFire(){
	if(k==bulletArray.length){
		if(personPoint.y=="13"||personPoint.x=="1"||personPoint.y=="1"||personPoint.x=="11"){
			clearInterval(fireBullet);
			bulletArray.length=0;
			k=1;
		}else{
			clearInterval(fireBullet);
			document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
			bulletArray.length=0;
			k=1;
		}
	}else{
	//贴脸
		if(k=="1"){
			switch(map[bulletArray[k].y][bulletArray[k].x]){
				case "symbol":
					clearInterval(fireBullet);
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/destory.gif";
					alert("You lost!")
					bulletArray.length=0;
					k=1;
				break;
				case "walls":
					clearInterval(fireBullet);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif"
					map[bulletArray[k].y][bulletArray[k].x]="black";
					clearInterval(comMove);
					bulletArray.length=0;
					k=1;
				break;
				case "enemy1D":
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/blast.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					number=number+100;
					document.getElementById("span1").innerHTML=number;
					clearInterval(fireBullet);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif"
					map[bulletArray[k].y][bulletArray[k].x]="black";
					clearInterval(comMove);
					bulletArray.length=0;
					k=1;
					computerPoint.x=3;
					computerPoint.y=1;
					comMove=setInterval("computerMove()",1000);
					setInterval("redom()",1000)
				break;
				case "enemy1D1":
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/blast.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					number=number+100;
					document.getElementById("span1").innerHTML=number;
					clearInterval(fireBullet);
					
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif"
					map[bulletArray[k].y][bulletArray[k].x]="black";
					clearInterval(comMove1);
					bulletArray.length=0;
					k=1;
					computerPoint1.x=3;
					computerPoint1.y=1;
					comMove=setInterval("computerMove1()",1000);
					setInterval("redom1()",1000)
				break;
				case "black":
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/tankmissile.gif"
					map[bulletArray[k].y][bulletArray[k].x]="black";
					k++;
				break;
				default:
					clearInterval(fireBullet);
					bulletArray.length=0;
					k=1;
				break;
			}
		}else{
	//不贴脸
			switch(map[bulletArray[k].y][bulletArray[k].x]){
				case "walls":
					clearInterval(fireBullet);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif";
					map[bulletArray[k].y][bulletArray[k].x]="black";
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
					bulletArray.length=0;
					k=1;
				break;
				case "enemy1D":
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/blast.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					number=number+100;
					document.getElementById("span1").innerHTML=number;
					clearInterval(fireBullet);
					clearInterval(comMove);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif";
					map[bulletArray[k].y][bulletArray[k].x]="black";
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
					bulletArray.length=0;
					k=1;
					//31 91
					computerPoint.x=3;
					computerPoint.y=1;
					comMove=setInterval("computerMove()",1000);
					setInterval("redom()",1000)
				break;
				case "enemy1D1":
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/blast.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					var num=document.getElementById("num")
					var music=document.createElement("embed");
					music.src="mp3/blast.wav";
					music.width="0";
					music.height="0";
					num.appendChild(music);
					number=number+100;
					document.getElementById("span1").innerHTML=number;
					clearInterval(fireBullet);
					clearInterval(comMove1);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/black.gif";
					map[bulletArray[k].y][bulletArray[k].x]="black";
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
					bulletArray.length=0;
					k=1;
					computerPoint1.x=9;
					computerPoint1.y=1;
					comMove1=setInterval("computerMove1()",1000);
					setInterval("redom()",1000)
				break;
				case "symbol":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					clearInterval(fireBullet);
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/destory.gif";
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
					alert("You lost!")
					bulletArray.length=0;
					k=1;
				break;
				case "steels":
					clearInterval(fireBullet);
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif";
					bulletArray.length=0;
					k=1
				break;
				case "black":
					document.getElementById(bulletArray[k].x+"-"+bulletArray[k].y).src="img/tankmissile.gif"
					map[bulletArray[k].y][bulletArray[k].x]=="black";
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif"
					k++;
				break;
				default:
					document.getElementById(bulletArray[k-1].x+"-"+bulletArray[k-1].y).src="img/black.gif"
					clearInterval(fireBullet);
					bulletArray.length=0;
					k=1;
				break;
			}
		}
	}
}
//判断下个位置是否可以移动并移动
function nextPointValue(obj){
	switch(map[obj.y][obj.x]){
		case "black":
//欺骗用户,视觉效果的移动
			document.getElementById(obj.x+"-"+obj.y).src="img/p1tankU.gif";
			document.getElementById(personPoint.x+"-"+personPoint.y).src="img/black.gif";
//实际地图数据的变化
			map[personPoint.y][personPoint.x]="black";
			map[obj.y][obj.x]="p1tankU";
			personPoint.x=obj.x;
			personPoint.y=obj.y;
		break;
	}
}
//电脑AI-------------------------------------------电脑AI-----------------------------------------------------------电脑AI-------------------------
var computerPoint=new Object();
//随机数组
var first=[1,2,3,4]//方向
//AI移动
function computerMove(){
	//电脑方向随机数=0,1,2,3
	var comNextPoint=new Object();
	var com=parseInt(Math.random()*first.length)
	switch(com){
		case 0:
			comNextPoint.x=computerPoint.x-1;
			comNextPoint.y=computerPoint.y;
			comNextPointValue(comNextPoint);
			document.getElementById(computerPoint.x+"-"+computerPoint.y).src="img/enemy1L.gif";
			directionAI=1;
		break;
		case 1:
			comNextPoint.x=computerPoint.x;
			comNextPoint.y=computerPoint.y-1;
			comNextPointValue(comNextPoint);
			document.getElementById(computerPoint.x+"-"+computerPoint.y).src="img/enemy1U.gif";
			directionAI=2;
		break;
		case 2:
			comNextPoint.x=computerPoint.x+1;
			comNextPoint.y=computerPoint.y;
			comNextPointValue(comNextPoint);
			document.getElementById(computerPoint.x+"-"+computerPoint.y).src="img/enemy1R.gif";
			directionAI=3;
		break;
		case 3:
			comNextPoint.x=computerPoint.x;
			comNextPoint.y=computerPoint.y+1;
			comNextPointValue(comNextPoint);
			document.getElementById(computerPoint.x+"-"+computerPoint.y).src="img/enemy1D.gif";
			directionAI=4;
		break;
	}
}
//判断AI下个位置是否可以移动
function comNextPointValue(obj){
	switch(map[obj.y][obj.x]){
		case "black":
//欺骗用户,视觉效果的移动
			document.getElementById(obj.x+"-"+obj.y).src="img/enemy1D.gif";
			document.getElementById(computerPoint.x+"-"+computerPoint.y).src="img/black.gif";
			
//实际地图数据的变化
			map[computerPoint.y][computerPoint.x]="black";
			map[obj.y][obj.x]="enemy1D";
			computerPoint.x=obj.x;
			computerPoint.y=obj.y;
		break;
	}
}
//AI射击
var bulletArrayAI=new Array();
var directionAI=4;
var fireBulletAI;
var bulletDirectionAI;
var g=1;
function redom(){
	var com=parseInt(Math.random()*first.length)
	if(bulletArrayAI.length!=0){
			
	}else{
		switch(com){
		case 1:
			bulletAI();
		break;
		}	
	}
}
//AI的子弹路径
function bulletAI(){

	//记录子弹方向
	bulletDirectionAI=directionAI;

	//记录子弹位置
	var	nextBullet=new Object();
	nextBullet.x=computerPoint.x;
	nextBullet.y=computerPoint.y;
	switch(bulletDirectionAI){
		case 1:
			for(var i=0;i<(nextBullet.x );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x-i;
				nextBulletPoint.y=nextBullet.y;
				bulletArrayAI.push(nextBulletPoint)
			}
		break;	
		case 2:
			for(var i=0;i<(nextBullet.y );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y-i;
				bulletArrayAI.push(nextBulletPoint)
			}
		break;	
		case 3:
			for(var i=0;i<(map[lv].length-nextBullet.x-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x+i;
				nextBulletPoint.y=nextBullet.y;
				bulletArrayAI.push(nextBulletPoint)
			}
		break;	
		case 4:
			for(var i=0;i<(map.length-nextBullet.y-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y+i;
				bulletArrayAI.push(nextBulletPoint)
			}
		break;	
	}
	fireBulletAI=setInterval("openFireAI()",300);	
}

//AI随机射击
function openFireAI(){
	if(g==bulletArrayAI.length){
		if(computerPoint.y=="13"||computerPoint.x=="1"||computerPoint.y=="1"||computerPoint.x=="11"){
			clearInterval(fireBulletAI);
			bulletArrayAI.length=0;
			g=1;
		}else{
			document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif";
			clearInterval(fireBulletAI);
			bulletArrayAI.length=0;
			g=1;
		}
	}else{
	//贴脸
		if(g=="1"){
			switch(map[bulletArrayAI[g].y][bulletArrayAI[g].x]){
				case "symbol":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/destory.gif";
					alert("You lost!")
					bulletArrayAI.length=0;
					g=1;
				break;
				case "walls":
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/black.gif"
					map[bulletArrayAI[g].y][bulletArrayAI[g].x]="black";
					bulletArrayAI.length=0;
					g=1;
				break;
				case "enemy1D":
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/enemy1D.gif"
					map[bulletArrayAI[g].y][bulletArrayAI[g].x]="enemy1D";
					bulletArrayAI.length=0;
					g=1;
					
				break;
				case "p1tankU":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					alert("You Death!")
					clearInterval(fireBulletAI);
					bulletArrayAI.length=0;
					g=1;
				break;
				
				case "black":
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/enemymissile.gif"
					map[bulletArrayAI[g].y][bulletArrayAI[g].x]="black";
					g++;
				break;
				default:
					clearInterval(fireBulletAI);
					bulletArrayAI.length=0;
					g=1;
				break;
			}
		}else{
	//不贴脸
			switch(map[bulletArrayAI[g].y][bulletArrayAI[g].x]){
				case "walls":
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/black.gif";
					map[bulletArrayAI[g].y][bulletArrayAI[g].x]="black";
					document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif";
					bulletArrayAI.length=0;
					g=1;
				break;
				case "p1tankU":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					alert("You Death!")
					clearInterval(fireBulletAI);
					bulletArrayAI.length=0;
					g=1;
				break;
				
				case "symbol":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/destory.gif";
					document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif";
					alert("You lost!")
					bulletArrayAI.length=0;
					g=1;
				break;
				case "steels":
					clearInterval(fireBulletAI);
					document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif";
					bulletArrayAI.length=0;
					g=1
				break;
				case "black":
					document.getElementById(bulletArrayAI[g].x+"-"+bulletArrayAI[g].y).src="img/enemymissile.gif"
					map[bulletArrayAI[g].y][bulletArrayAI[g].x]=="black";
					document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif"
					g++;
				break;
				default:
					document.getElementById(bulletArrayAI[g-1].x+"-"+bulletArrayAI[g-1].y).src="img/black.gif";
					clearInterval(fireBulletAI);
					bulletArrayAI.length=0;
					g=1;
				break;
			}
		}
	}
}
//第二个AI
var computerPoint1=new Object();
//AI移动
function computerMove1(){
	//电脑方向随机数=0,1,2,3
	var comNextPoint=new Object();
	var com=parseInt(Math.random()*first.length)
	switch(com){
		case 0:
			comNextPoint.x=computerPoint1.x-1;
			comNextPoint.y=computerPoint1.y;
			comNextPointValue1(comNextPoint);
			document.getElementById(computerPoint1.x+"-"+computerPoint1.y).src="img/enemy1L.gif";
			directionAI1=1;
		break;
		case 1:
			comNextPoint.x=computerPoint1.x;
			comNextPoint.y=computerPoint1.y-1;
			comNextPointValue1(comNextPoint);
			document.getElementById(computerPoint1.x+"-"+computerPoint1.y).src="img/enemy1U.gif";
			directionAI1=2;
		break;
		case 2:
			comNextPoint.x=computerPoint1.x+1;
			comNextPoint.y=computerPoint1.y;
			comNextPointValue1(comNextPoint);
			document.getElementById(computerPoint1.x+"-"+computerPoint1.y).src="img/enemy1R.gif";
			directionAI1=3;
		break;
		case 3:
			comNextPoint.x=computerPoint1.x;
			comNextPoint.y=computerPoint1.y+1;
			comNextPointValue1(comNextPoint);
			document.getElementById(computerPoint1.x+"-"+computerPoint1.y).src="img/enemy1D.gif";
			directionAI1=4;
		break;
	}
}
//判断AI下个位置是否可以移动
function comNextPointValue1(obj){
	switch(map[obj.y][obj.x]){
		case "black":
//欺骗用户,视觉效果的移动
			document.getElementById(obj.x+"-"+obj.y).src="img/enemy1D.gif";
			document.getElementById(computerPoint1.x+"-"+computerPoint1.y).src="img/black.gif";
			
//实际地图数据的变化
			map[computerPoint1.y][computerPoint1.x]="black";
			map[obj.y][obj.x]="enemy1D1";
			computerPoint1.x=obj.x;
			computerPoint1.y=obj.y;
		break;
	}
}
//AI射击
var bulletArrayAI1=new Array();
var directionAI1=4;
var fireBulletAI1;
var bulletDirectionAI1;
var r=1;
function redom1(){
	var com=parseInt(Math.random()*first.length)
	if(bulletArrayAI1.length!=0){
			
	}else{
		switch(com){
		case 1:
			bulletAI1();
		break;
		}	
	}
}
//AI的子弹路径
function bulletAI1(){
	//记录方向
	bulletDirectionAI1=directionAI1;
	//记录角色位置
	var	nextBullet=new Object();
	nextBullet.x=computerPoint1.x;
	nextBullet.y=computerPoint1.y;
	switch(bulletDirectionAI1){
		case 1:
			for(var i=0;i<(nextBullet.x );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x-i;
				nextBulletPoint.y=nextBullet.y;
				bulletArrayAI1.push(nextBulletPoint)
			}
		break;	
		case 2:
			for(var i=0;i<(nextBullet.y );i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y-i;
				bulletArrayAI1.push(nextBulletPoint)
			}
		break;	
		case 3:
			for(var i=0;i<(map[lv].length-nextBullet.x-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x+i;
				nextBulletPoint.y=nextBullet.y;
				bulletArrayAI1.push(nextBulletPoint)
			}
		break;	
		case 4:
			for(var i=0;i<(map.length-nextBullet.y-1);i++){
				var nextBulletPoint=new Object();
				nextBulletPoint.x=nextBullet.x;
				nextBulletPoint.y=nextBullet.y+i;
				bulletArrayAI1.push(nextBulletPoint)
			}
		break;	
	}
	fireBulletAI1=setInterval("openFireAI1()",300);	
}

//AI随机射击
function openFireAI1(){
	if(r==bulletArrayAI1.length){
		if(computerPoint1.y=="13"||computerPoint1.x=="1"||computerPoint1.y=="1"||computerPoint1.x=="11"){
			clearInterval(fireBulletAI1);
			bulletArrayAI1.length=0;
			r=1;
		}else{
			document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif";
			clearInterval(fireBulletAI1);
			bulletArrayAI1.length=0;
			r=1;
		}
	}else{
	//贴脸
		if(r=="1"){
			switch(map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]){
				case "symbol":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/destory.gif";
					alert("You lost!")
					bulletArrayAI1.length=0;
					r=1;
				break;
				case "walls":
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/black.gif"
					map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]="black";
					bulletArrayAI1.length=0;
					r=1;
				break;
				case "enemy1D":
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/enemy1D.gif"
					map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]="enemy1D";
					bulletArrayAI1.length=0;
					r=1;
				break;
				case "p1tankU":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					alert("You Death!")
					clearInterval(fireBulletAI1);
					bulletArrayAI1.length=0;
					r=1;
				break;
				
				case "black":
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/enemymissile.gif"
					map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]="black";
					r++;
				break;
				default:
					clearInterval(fireBulletAI1);
					bulletArrayAI1.length=0;
					r=1;
				break;
			}
		}else{
	//不贴脸
			switch(map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]){
				case "walls":
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/black.gif";
					map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]="black";
					document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif";
					bulletArrayAI1.length=0;
					r=1;
				break;
				case "p1tankU":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					alert("You Death!")
					clearInterval(fireBulletAI1);
					bulletArrayAI1.length=0;
					r=1;
				break;
				
				case "symbol":
					clearInterval(comMove);
					clearInterval(comMove1);
					clearInterval(computerF);
					clearInterval(computerF1);
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/destory.gif";
					document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif";
					alert("You lost!")
					bulletArrayAI1.length=0;
					r=1;
				break;
				case "steels":
					clearInterval(fireBulletAI1);
					document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif";
					bulletArrayAI1.length=0;
					r=1
				break;
				case "black":
					document.getElementById(bulletArrayAI1[r].x+"-"+bulletArrayAI1[r].y).src="img/enemymissile.gif"
					map[bulletArrayAI1[r].y][bulletArrayAI1[r].x]=="black";
					document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif"
					r++;
				break;
				default:
					document.getElementById(bulletArrayAI1[r-1].x+"-"+bulletArrayAI1[r-1].y).src="img/black.gif";
					clearInterval(fireBulletAI1);
					bulletArrayAI1.length=0;
					r=1;
				break;
			}
		}
	}
}

//地图--------------------------------------------------地图---------------------------------------------------------地图---------------------------
function initMaps(){
	//横向13 	纵向15
	maps=[
			[
				["water","water","water","water","water","water","water","water","water","water","water","water","water"],
				["water","walls","enemy1D","black","black","black","black","black","black","black","enemy1D1","walls","water"],
				["water","walls","black","black","black","black","black","black","black","black","black","walls","water"],
				["water","walls","walls","black","walls","black","black","black","walls","black","walls","walls","water"],
				["water","black","walls","walls","walls","black","black","black","walls","walls","walls","black","water"],
				["water","black","walls","black","walls","black","black","black","walls","black","walls","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","steels","black","black","black","black","black","black","black","black","black","steels","water"],
				["water","black","black","black","steels","steels","steels","steels","steels","black","black","black","water"],
				["water","black","black","black","walls","black","black","black","walls","black","black","black","water"],
				["water","walls","walls","black","walls","walls","walls","walls","walls","black","walls","walls","water"],
				["water","walls","black","black","black","black","black","black","black","black","black","walls","water"],
				["water","walls","walls","black","black","walls","walls","walls","black","black","walls","walls","water"],
				["water","walls","black","black","p1tankU","walls","symbol","walls","black","black","black","walls","water"],
				["water","water","water","water","water","water","water","water","water","water","water","water","water"]
			],
			[
				["water","water","water","water","water","water","water","water","water","water","water","water","water"],
				["water","enemy1D","black","black","black","black","black","black","black","black","enemy1D1","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","black","walls","black","walls","black","black","black","walls","black","walls","black","water"],
				["water","black","walls","walls","walls","black","black","black","walls","walls","walls","black","water"],
				["water","black","walls","black","walls","black","black","black","walls","black","walls","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","steels","black","black","black","black","black","black","black","black","black","steels","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","black","black","black","black","black","black","black","black","black","black","black","water"],
				["water","black","black","black","black","walls","walls","walls","black","black","black","black","water"],
				["water","black","black","black","p1tankU","walls","symbol","walls","black","black","black","black","water"],
				["water","water","water","water","water","water","water","water","water","water","water","water","water"]
			]
		]
}
















